from datetime import datetime
from typing import Optional

from sqlalchemy import BIGINT
from sqlmodel import Field

from src.base.beans import PageParam, Datetime
from src.domain.base_model import DbBaseModel
from src.base.beans import Bigint


class SysTenantBase(DbBaseModel):
    tenant_id: Optional[Bigint] = Field(default=None, primary_key=True, description="租户序号", sa_type=BIGINT,
                                        sa_column_kwargs={"comment": "租户序号"})
    tenant_name: Optional[str] = Field(default=None, description="租户名称", sa_column_kwargs={"comment": "租户名称"})
    org_name: Optional[str] = Field(default=None, description="组织名称", sa_column_kwargs={"comment": "组织名称"})
    org_credit_code: Optional[str] = Field(default=None, description="组织信用代码",
                                           sa_column_kwargs={"comment": "组织信用代码"})
    org_phone: Optional[str] = Field(default=None, description="组织电话", sa_column_kwargs={"comment": "组织电话"})
    org_intro: Optional[str] = Field(default=None, description="组织电话", sa_column_kwargs={"comment": "组织电话"})
    expire_time: Optional[Datetime] = Field(default=None, description="到期时间",
                                            sa_column_kwargs={"comment": "到期时间"})
    account_count: Optional[int] = Field(default=None, description="账号数量",
                                         sa_column_kwargs={"comment": "账号数量", "server_default": "-1"})
    account_balance: Optional[float] = Field(default=None, description="余额",
                                             sa_column_kwargs={"comment": "余额", "server_default": "-1"})
    account_score: Optional[int] = Field(default=None, description="积分",
                                         sa_column_kwargs={"comment": "积分", "server_default": "-1"})


class SysTenant(SysTenantBase, table=True):
    __tablename__ = "sys_tenant"
    __table_args__ = {'extend_existing': True, 'comment': '租户表'}


class SysTenantReq(SysTenantBase, PageParam):
    create_time_range: Optional[list[str]] = Field(default=None, description="创建时间范围")
    update_time_range: Optional[list[str]] = Field(default=None, description="更新时间范围")


class SysTenantResp(SysTenantBase):
    pass
